package jp.dip.sys1.android.sharp.walkquest;

import jp.co.sharp.android.hardware.Pedometer;
import jp.dip.sys1.android.sharp.walkquest.data.SettingPreference;
import jp.dip.sys1.android.sharp.walkquest.util.Util;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class NewGame extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.new_game);
		Util.find(this, R.id.ok, Button.class).setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Pedometer pedometer = Pedometer.createInstance(NewGame.this);
				String name = Util.find(NewGame.this, R.id.name, EditText.class).getText().toString();
				if("".equals(name)){
					Toast.makeText(NewGame.this, getString(R.string.enter_name_text), Toast.LENGTH_SHORT).show();
				}
				else{
					SettingPreference pref = new SettingPreference(NewGame.this);
					pref.clear();
					pref.setName(name);
					pref.setOffset(pedometer.getIntParameter(Pedometer.STEPS));
					Intent intent = new Intent(NewGame.this, GameMain.class);
					startActivity(intent);
				}
			}
		});
	}
}
